﻿using CSharp.Libs.WPF.UserControls.SmartMediaPlayer.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CSharp.Libs.WPF.UserControls.SmartMediaPlayer
{
	/// <summary>
	/// Interaktionslogik für PlaylistControl.xaml
	/// </summary>
	public partial class PlaylistControl : UserControl
	{
		#region declarations
		private PlaylistViewModel _vm;
		#endregion



		#region constructor
		public PlaylistControl()
		{
			InitializeComponent();

			Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;

			_vm = new PlaylistViewModel();
			DataContext = _vm;
		}

		void Dispatcher_ShutdownStarted(object sender, EventArgs e)
		{
			Dispatcher.ShutdownStarted -= Dispatcher_ShutdownStarted;
			DataContext = null;
			_vm.Shutdown();
			_vm = null;
		}
		#endregion



		#region event handling
		private void lvItems_MouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			if (VM.PlaySelectedFile.CanExecute(null))
			{
				VM.PlaySelectedFile.Execute(null);
			}
		}
		#endregion



		#region properties
		public PlaylistViewModel VM { get { return _vm; } }
        #endregion 

		private void lvItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			VM.SelectedItems = lvItems.SelectedItems;
		}
	}
}
